// 语言包
var chi = require('../../utils/Chinese.js')
var eng = require("../../utils/English.js")
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    language: '',
    // 语言包对象
    content: '',
    list:[{id:"0",name:"大梨",tel:"13855554444",coders:'123456', add:"广东省深圳市南山区科兴科学院",default:true,select: "circle",},{id:"1",name:"小梨",tel:"13855554444",coders:'654321',add:"广东省深圳市南山区科兴科学院",default:false,select: "circle",}]
    },
    on: function () {
        let that = this
        that.setData({
            language: app.data.language,
        })
        var lastLanuage = that.data.language
        if (lastLanuage == 'zh_CN') {
            that.setData({
                content: chi.content,
            })
            wx.setNavigationBarTitle({
                title: '选择地址'
            })
        } else if (lastLanuage == 'zh_EN') {
            that.setData({
                content: eng.content,
            })
            // 修改导航标题
            wx.setNavigationBarTitle({
                title: 'Select Address'
            })
        }
    },
    //改变选框状态
  change: function (e) {
    var that = this
    //把新的值给新的数组
    var newList = that.data.list
    //得到下标
    var index = e.currentTarget.dataset.index
    console.log(index)
    //得到选中状态
    var select = e.currentTarget.dataset.select
    // 将所有icon初始化
    for (let i = 0; i < newList.length; i++) {
      newList[i].select='circle'
      
    }
    if (select == "circle") {
      var stype = "success"
    } else {
      var stype = "circle"
    }
    // 将地址传到app.js/posi
    app.data.posi = newList[index],
    app.data.add_show = true
    newList[index].select = stype
    //把新的数组传给前台
    that.setData({
      list: newList
    })
    wx.redirectTo({
      url: '../order_infor/order_infor',
    })
  },
  // 添加子新地址
  newAdd:function(){
    wx.redirectTo({
      url: '../new_address/new_address',
    })
  },
  // 编辑地址
  edit:function(e){
    console.log(e)
    let that = this 
    var idx = e.currentTarget.dataset.id
    var lis = that.data.list
    app.data.add_edit  = lis[idx]
    console.log(lis[idx])
    wx.navigateTo({
      url: '../add_edit/add_edit',
    })
    
  },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this
        that.on()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let that = this
        that.on()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})